﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex03.GarageLogic
{
    public class Bike : Vehicle
    {
        private const int k_BikeMinimalEngineVolume = 0;

        public enum eBikePermitType
        {
            DefaultValue = 0,
            A,
            A1,
            A2,
            B
        }
        
        private eBikePermitType m_BikePermitTypeNeeded;
	    private int m_BikeEngineVolume;

        public Bike(
            string i_BikeModelName,
            string i_BikeLicenseNumber, 
            int i_BikeWheelAmount, 
            float i_BikeWheelMaximumAirPressure,
            eBikePermitType i_BikePermitType, 
            int i_BikeEngineVolume) 
            : base(
            i_BikeModelName,
            i_BikeLicenseNumber, 
            i_BikeWheelAmount, 
            i_BikeWheelMaximumAirPressure)
        {
            if (!isBikePermitLegal(i_BikePermitType))
            {
                ArgumentException BikePermitError = new ArgumentException();

                throw BikePermitError;
            }
            else if (!isBikeEngineVolumeLegal(i_BikeEngineVolume))
            {
                ValueOutOfRangeException BikeEngineVolumeError = new ValueOutOfRangeException();

                throw BikeEngineVolumeError;
            }
            else
            {
                m_BikePermitTypeNeeded = i_BikePermitType;
                m_BikeEngineVolume = i_BikeEngineVolume;
            }
        }

        /// <summary>
        /// This method checks the legality of the bike's permit type from the possible allowed types (eBikePermitType).
        /// </summary>
        /// <param name="i_BikePermitType">
        /// This variable is of type "eBikePermitType", which is declared in the current file above.
        /// </param>
        /// <returns></returns>
        private bool isBikePermitLegal(eBikePermitType i_BikePermitType)
        {
            bool ReturnValue = false;

            switch (i_BikePermitType)
            { 
                case eBikePermitType.A:
                case eBikePermitType.A1:
                case eBikePermitType.A2:
                case eBikePermitType.B:
                case eBikePermitType.DefaultValue:
                    ReturnValue = true;
                    break;
                default:
                    break;
            }

            return ReturnValue;
        }

        /// <summary>
        /// This method checks that the bike's entered engine volume is legal (greater than zero).</summary>
        /// <param name="i_BikeEngineVolume">
        /// This parameter holds the is the initializing engine volume.</param>
        /// <value>
        /// This is the value.</value>
        /// <returns></returns>
        private bool isBikeEngineVolumeLegal(int i_BikeEngineVolume)
        {
            bool ReturnValue = false;

            if (i_BikeEngineVolume > k_BikeMinimalEngineVolume)
            {
                ReturnValue = true;
            }

            return ReturnValue;
        }
        
        public int BikeEngineVolume
        {
            get { return m_BikeEngineVolume; }
            set
            {
                if (!isBikeEngineVolumeLegal(value))
                {
                    ValueOutOfRangeException BikeEngineVolumeError = new ValueOutOfRangeException();

                    throw BikeEngineVolumeError;
                }
                else
                {
                    m_BikeEngineVolume = value;
                }
            }
        }

        public eBikePermitType BikePermitType
        {
            get { return m_BikePermitTypeNeeded; }
            set
            {
                if (!isBikePermitLegal(value))
                {
                    ArgumentException BikePermitError = new ArgumentException();

                    throw BikePermitError;
                }
                else
                {
                    m_BikePermitTypeNeeded = value;
                }
            }
        }

        virtual public override bool AddPropulsionMaterial(
            EnergyType.eEnergyType i_PropulsionMaterialType, 
            float i_PropulsionMaterialAmountToAdd)
        {
            throw new NotImplementedException();
        }

        //public override List<String> CollectQustionsListToAskUser()
        //{
        //    List<String> Qustions = new List<String>();
        //    Qustions = base.CollectQustionsListToAskUser();
        //    Qustions.Add(String.Format("Enter Engine Volume :"));
        //    Qustions.Add(String.Format("Enert Permit Type Needed (A, A1, A2, B):"));

        //    return Qustions;
        //}

        //public override void GetStringsFromUserAndUpdateVehicleData(List<String> i_Answers)
        //{
        //    int engineVolumeInput;
        //    base.GetStringsFromUserAndUpdateVehicleData(i_Answers);
        //    try
        //    {
        //        engineVolumeInput = int.Parse(i_Answers[0]);
        //        if (isInitializingEngineVolumeLegal(engineVolumeInput))
        //        {
        //            EngineVolume = engineVolumeInput;
        //        }
        //        else
        //        {
        //            throw new Exception("Engine Volume is out of range");
        //        }
        //    }
        //    catch (FormatException ex)
        //    {
        //        throw new FormatException("Engine Volume Format Error",ex);
        //    }
        //    try
        //    {
        //        PermitTypeNeeded = (eBikePermitType)Enum.Parse(typeof(eBikePermitType), i_Answers[1].ToUpper());
        //    }
        //    catch
        //    {
        //        throw new FormatException("Error With Permit Type Format");
        //    }

        //    finally
        //    {
        //        i_Answers.RemoveRange(0, 2);
        //    }
        //}

        //public override List<string> GetAllInformation()
        //{
        //    List<String> ReturnValue = null;
        //    ReturnValue = base.GetAllInformation();
        //    if (ReturnValue == null)
        //    {
        //        ReturnValue = new List<String>();
        //    }

        //    ReturnValue.Add(String.Format("Engine Volume: {0}",EngineVolume));
        //    ReturnValue.Add(String.Format("Permit Type Needed: {0}", PermitTypeNeeded));
        //    return ReturnValue;
        //}
    }
}
